#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        int len = nums.size();
        int slow = 0; int fast = 0; int mid = 0;
        while (fast < len) {
            while (fast < len && nums[mid] == nums[fast]) {
                fast++;
            }
            int tmp = 0;
            while (mid < fast && tmp < 2) {
                nums[slow] = nums[mid];
                mid++; slow++; tmp++;
            }
            mid = fast;
            // fast++;
            // fast++;
        }
        return slow;
    }
};